import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ConnectException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


/*
 @Sangeeta
 *Uses: This program is used to remove stop word from the title, description  and file path
 */

public class tf_idf_remove_stop 
{
  public Connection conn  =  null;	
  public String dbname = "jboss";
  public String userid = "root";
  public String passwd = "123";

  public void process_title_desc(Connection conn)
  {
	//Connection conn  =null;
		Statement stmt=null;
		
		//selecting only selected Bugs 
		String q= "select * from  tdfp_match_score";
		
		try
		  {
			 stmt=conn.createStatement();
			 stmt.execute(q);
		     ResultSet rs =  stmt.getResultSet();
		     
		     int count=1;
		     while(rs.next())
		       {
		    	 
		    	
		            String bugid=rs.getString("bugid");
		            String nfid = rs.getString("nfid");
		            
		            
		    	    ngram_match ng = new ngram_match();
		      
		    		String title=ng.get_title(bugid,conn);
		    		String desc= ng.get_desc(bugid,conn);
		    	    String file_name = ng.get_fname(nfid, conn);
		    	    String file_path =  ng.get_file_path(nfid, conn);
		    				
		    		System.out.println("title="+title);
		    		System.out.println("Desc="+desc);
		    		System.out.println("Fname="+file_name);
		    		System.out.println("File path="+file_path);
		    		
		    		general_fun gf= new general_fun();
		    	 
		    		title=gf.clean(title);
		    		desc=gf.clean(desc);
		    	 
		    		title=gf.remove_stop_words(title);
		    		desc=gf.remove_stop_words(desc);
		    	 
		    	    title=gf.remove_SW(title);
		    		desc=gf.remove_SW(desc);
		    		
		    		System.out.println("----------------------");
		    		System.out.println("clean Title="+title);
                    System.out.println("Clean desc="+desc);
		    		
		    		
		            System.out.println("count="+count);
		    		count++;
		    		
		    		intr();
		    	
		    		System.out.println("========================");
		    
		      
		       }//wh
			 
		  
		     if(rs!=null)
		    	 rs.close();
		     
		     if(stmt!=null)
		    	 stmt.close();
		  
		  } catch (SQLException e) 
		  { 	e.printStackTrace(); 	}
		
		
  }//
  
  
  public void intr()
  {
 	 BufferedReader br =  new BufferedReader(new InputStreamReader(System.in));
 	 System.out.println("INTR");
 	 try {
 		br.readLine();
 	} catch (IOException e) {
 		// TODO Auto-generated catch block
 		e.printStackTrace();
 	}
 	 
  }//intr
  
  public static void main(String  args[])
  {
	 db_conn db =  new db_conn();
	 tf_idf_remove_stop obj =  new tf_idf_remove_stop();
	 obj.conn=db.connect(obj.dbname, obj.userid, obj.passwd);
	 
	 obj.process_title_desc(obj.conn);
	 db.close(obj.conn);
	  
  }//main
}
